/**
 * key：路由的name
 * value: {
 *      exclude: 不清楚缓存的的路由名称  清除缓存的白名单
 *      cacheIds: 要清楚的缓存key值数组
 * }
 */
const clearRouteTable = {
  AccessPointConfig: {
    exclude: ["AccessPointGatewayConfig"],
    cacheIds: ["accessPointList", "accessPointBaseConfig", "bandWidthJson"]
  },
  AccessPointGatewayConfig: {
    exclude: ["AccessPointConfig", "AccessPointNATConfig"],
    cacheIds: ["accessPointList", "accessPointBaseConfig", "bandWidthJson"]
  },
  AccessPointNATConfig: {
    exclude: ["AccessPointGatewayConfig", "OrderConfirm"],
    cacheIds: ["accessPointList", "accessPointBaseConfig", "bandWidthJson"]
  },
  OrderConfirm: {
    exclude: ["AccessPointNATConfig", "MoreConfig"],
    cacheIds: ["accessPointList", "accessPointBaseConfig", "bandWidthJson"]
  },
  MoreConfig: {
    exclude: ["OrderConfirm"],
    cacheIds: ["accessPointList", "accessPointBaseConfig", "bandWidthJson"]
  },
  ModifyAccessPoint: {
    exclude: [],
    cacheIds: ["businessId", "businessInfo"]
  },
  EditOrder: {
    exclude: [],
    cacheIds: ["orderInfo"]
  }
};

// 清楚页面 sessionStorage 缓存
export default (fromRouteName, toRouteName) => {
  if (!fromRouteName) {
    return;
  }
  let { exclude = [], cacheIds = [] } = clearRouteTable[fromRouteName] || {};
  if (exclude.indexOf(toRouteName) !== -1) {
    return;
  }
  cacheIds.forEach(cacheId => {
    sessionStorage.getItem(cacheId) && sessionStorage.removeItem(cacheId);
  });
};
